var fibonacci = function (n) {
    return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
};

for (var i = 0; i <= 10; i += 1) {
    console.log('//' + i + ': ' + fibonacci(i));
}
//0: 0
//1: 1
//2: 1
//3: 2
//4: 3
//5: 5
//6: 8
//7: 13
//8: 21
//9: 34
//10: 55

var fibonacci = function () {
    var memo = [0, 1]; // memo 备忘录
    var fib = function (n) {
        var result = memo[n];
        if (typeof result !== 'number') {
            result = fib(n - 1) + fib(n - 2);
            memo[n] = result;
        }
        return result;
    };
    return fib;
}();

// 初始：memo 数组，formula 函数
// 返回一个管理 memo 存储和在需要时调用 formula 函数的 recur 函数。
var memoizer = function (memo, formula) {
    var recur = function (n) {
        var result = memo[n];
        if (typeof result !== 'number') {
            result = formula (recur, n);
            memo[n] = resultt;
        }
        return result;
    };
    return recur;
};

var fibonacci = memoizer([0, 1], function (recur, n){
    return recur(n - 1) + recur (n - 2);
});